Skip to content

Conversation

@sunag
Copy link
Collaborator

@sunag sunag commented Nov 17, 2023

Related issue: #26704

Description

varyingProperty declares varying without having to set an initial value as in varying, thus saving GPU resources.

This was used in some specific cases, such as Line2NodeMaterial and can now be used directly in WGSL if necessary.

const myVarying = varyingProperty( 'vec3', 'myVarying' );

const positionTransformFn = wgslFn( `
	fn positionTransformFn( position: vec3<f32> ) -> vec3<f32> {

		// varyings.* is the structure that will store all the varyings
		// you can use it to access/store your varying value

		varyings.myVarying = position;

		return position;

	}
`, [ myVarying ] );

material = new MeshBasicNodeMaterial();
material.colorNode = myVarying;
material.positionNode = positionTransformFn( { position: positionLocal } );

@sunag sunag added the TSL Three.js Shading Language label Nov 17, 2023
@sunag sunag added this to the r159 milestone Nov 17, 2023
@sunag
Copy link
Collaborator Author

sunag commented Nov 17, 2023

/cc @Spiri0

@sunag sunag marked this pull request as ready for review November 17, 2023 03:56
@sunag sunag merged commit 997c8b5 into mrdoob:dev Nov 17, 2023
@sunag sunag deleted the dev-varyingProperty branch November 17, 2023 08:06
AdaRoseCannon pushed a commit to AdaRoseCannon/three.js that referenced this pull request Jan 15, 2024
* TSL: varyingProperty

* update example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

TSL Three.js Shading Language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant